package my.Interceptor.allow_origin;

import javax.servlet.http.HttpServletResponse;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * 允许跨域访问切面
 * @author xsw
 * @date 2017-10-25
 */
@Aspect
@Component
public class AspectAllowOrigin {
	@Autowired
    private HttpServletResponse response;
	/**
	 * 切入点
	 */
	@Pointcut("@within(my.Interceptor.allow_origin.AllowOrigin)")
    private void adviceAllowOrigin(){}
    
    /**
     * 
     * @param point
     * @return
     */
//	@Order(2)
    @AfterReturning(value="adviceAllowOrigin()")
    public void afterReturning(){
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		response.setHeader("Access-Control-Allow-Headers", "x-requested-with,content-type");
    }
}
